local baihuaqifang = fk.CreateSkill{
    name = "rmt__baihuaqifang",
    tags = {Skill.Hidden}
}
Fk:loadTranslationTable{
    ["rmt__baihuaqifang"] = "百花齐放",
    [":rmt__baihuaqifang"] = "隐匿。你登场时，从四张同名武将中选择一张登场。",
}

local U = require "packages.utility.utility"

baihuaqifang:addEffect(U.GeneralAppeared, {
    can_refresh = function (self, event, target, player, data)
        local tName = Fk.generals[player.general].trueName
        local ret = Fk.same_generals[tName] or {}
        if data.extra_data and data.extra_data.rmt__baihuaqifang then return end
        return player:hasSkill(baihuaqifang.name) and player == target and #table.filter(ret, function(g)
            return g ~= player.general and Fk.generals[g] ~= nil and not table.contains(Fk:currentRoom().disabled_generals, g)
        end) > 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        room:notifySkillInvoked(player,self.name,"special")
        local tName = Fk.generals[player.general].trueName
        local ret = Fk.same_generals[tName] or {}
        local sameGenerals = table.filter(ret, function(g)
            return g ~= player.general and Fk.generals[g] ~= nil and not table.contains(Fk:currentRoom().disabled_generals, g)
        end)
        local general = room:askToChooseGeneral(player, {
            n = 1,
            generals = table.random(sameGenerals, 4),
            no_convert = true,
        })
        room:findGeneral(general)
        room:changeHero(player, general, false, false, true, true)

        local event_data = {["m"] = general}
        local deputy = Fk.generals[player.deputyGeneral]
        if deputy then
            room:sendLog{ type = "#RevealGeneral", from = player.id, arg =  "deputyGeneral", arg2 = deputy.name }
            event_data["d"] = deputy.name
        end
        event_data.extra_data = {}
        event_data.extra_data.rmt__baihuaqifang = true
        room.logic:trigger(U.GeneralAppeared, player, event_data)
    end,
})

baihuaqifang:addEffect(fk.Deathed, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        return target and table.contains({"rmtLv2__lvbao","rmtLv3__lvbao","rmtLv4__lvbao","rmtLv5__lvbao","rmtLv6__lvbao","rmtLv7__lvbao","rmtLv8__lvbao","rmtLv9__lvbao","rmtLv10__lvbao"},target.general)
    end,
    on_refresh = function (self, event, target, player, data)
        player.room:broadcastPlaySound("./packages/aaa_Romantic/audio/death/rmt__lvbao")
    end,
})

return baihuaqifang